<template>
  <div class="flex">
    <form class="form-inline">
      <div class="form-group">
        <label for="c_plan_year">年份：</label>
        <v-select id="c_plan_year" :value.sync="c_plan_year"
        :options='c_year_list' close-on-select clear-button></v-select>
        <label for="c_plan_month">月份：</label>
        <v-select id="c_plan_month" :value.sync="c_plan_month"
        :options='c_month_list' close-on-select clear-button></v-select>
        <!-- <button type="button" class="btn btn-default" @click="search()">查询</button> -->
      </div>
      <div class="form-group">
           <button type="button" class="btn btn-success width-80" @click="search()">查询</button>
      </div>
      <div class="form-group">
        部门:
        <chooser :userid.sync='loginer.id' resource-type="organization" class="bg-variant" :width='200' :select-data.sync='model.chosenOrg'></chooser>
      </div>
      {{model.chosenOrg.fullname}}
    </form>
    <div class="span">
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>安检员</th>
            <th>任务</th>
            <th>已完成</th>
          </tr>
        </template>
        <template partial='body'>
          <td>{{row.f_checker}}</td>
          <td>{{row.task}}</td>
          <td>{{row.accomplished}}</td>
        </template>
      </data-grid>
    </span>
    <div style="height:50px;"></div>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import Vue from 'vue'
import * as Util from '../Util'
export default {
  title: '安检员月任务',
  // props: ['f'],
  data() {
    let options = []
    let year = (new Date()).getFullYear()
    for(let i = year - 8; i <= year +1; i++ )
      options.push({label: i+'', value: i+''})
    let moptions = []
    for(let i=1; i<=12; i++)
      moptions.push({label: i + '', value: i + ''})
    let model = new PagedList('rs/rcq/跟踪安检员月任务', 20,
    {id: 'this.id', org_id: 'this.chosenOrg.id', f_plan_year: 'this.f_plan_year', f_subcompany: 'this.f_subcompany',
    f_plan_month: 'this.f_plan_month', f_ym: 'this.f_ym'})
    model.chosenOrg = {id:0}
    return {
      c_plan_year: year + '',
      c_year_list: options,
      c_month_list: moptions,
      c_plan_month: moptions[new Date().getMonth()].value,
      model: model,
      loginer: Util.f
    }
  },
  ready () {
    this.model.id = this.loginer.id
    this.model.chosenOrg.id = this.loginer.parent.id
    this.model.f_plan_year = this.c_plan_year[0]
    this.model.f_plan_month = this.c_plan_month[0]
    this.model.f_subcompany = Vue.f_subcompany
    this.model.f_ym = this.c_plan_year[0] + '-' + (this.c_plan_month[0].length > 1 ? this.c_plan_month[0] : '0' + this.c_plan_month[0])
    this.$watch('c_plan_year', function (val) {
        this.model.f_plan_year = val[0]
        this.model.f_ym = val[0] + '-' + (this.c_plan_month[0].length > 1 ? this.c_plan_month[0] : '0' + this.c_plan_month[0])
    })
    this.$watch('c_plan_month', function (val) {
        this.model.f_plan_month = val[0]
        this.model.f_ym = this.c_plan_year[0] + '-' + (val[0].length > 1 ? val[0] : '0' + val[0])
    })
  },
  methods: {
    search () {
      this.model.rows = []
      this.model.search()
    }
  }
}
</script>
